package com.gopay.common.report.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.report.Event;
import com.gopay.common.report.dao.MqEventInfoDAO;

/**
 * @MqEventInfoDAOImpl.java
 * @author fanghw
 * @2015年6月12日 下午4:46:02  www.gopay.com.cn Inc.All rights reserved.
 */
public class MqEventInfoDAOImpl extends BaseDAOImpl<Event, Integer>  implements MqEventInfoDAO {

    @Override
    public void batchSave(List<Event> eventList) {
        SessionFactory sessionFactory = this.getHibernateTemplate().getSessionFactory();
        Session session = sessionFactory.openSession();
        Transaction tx = session.beginTransaction();     
        for ( int i=0; i<eventList.size(); i++ ) { //插入100万条数据  
            Event e = eventList.get(i);
            session.save(e);
            if(i%50 == 0){
                session.flush();
                session.clear();
            }
        }     
        tx.commit();   
        session.close();  
    }
}
